﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using LeagueOfRila.Model;
using Data;
using Data.Characters;
using Microsoft.Xna.Framework.Audio;

namespace LeagueOfRila.View
{
    public class MenuCharacterChoiceView : BaseView
    {

        Texture2D backgroundImage;
        Texture2D btn_right;
        Texture2D btn_right_click;
        Texture2D btn_left;
        Texture2D btn_left_click;
        Texture2D characterImage;
        Texture2D backgroundGetReady;
        public SpriteFont font2;
        

        public MenuCharacterChoiceModel GetModel()
        {
            return this.model as MenuCharacterChoiceModel;
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            base.LoadContent();
            font2 = Content.Load<SpriteFont>("SpriteFont2");
            this.backgroundImage = Content.Load<Texture2D>("MenuCharacter/background");
            this.btn_left = Content.Load<Texture2D>("MenuCharacter/btn_gauche");
            this.btn_left_click = Content.Load<Texture2D>("MenuCharacter/btn_gauche_hover");
            this.btn_right = Content.Load<Texture2D>("MenuCharacter/btn_droite");
            this.btn_right_click = Content.Load<Texture2D>("MenuCharacter/btn_droite_hover");
            this.backgroundGetReady = Content.Load<Texture2D>("MenuCharacter/backgroundGetReady");

            //sons personnages
            Client.rogueReady = Content.Load<SoundEffect>("Sounds/Rogue/rogueReady");
            Client.priestReady = Content.Load<SoundEffect>("Sounds/Priest/priestReady");
            Client.warReady = Content.Load<SoundEffect>("Sounds/War/warReady");
            Client.mageReady = Content.Load<SoundEffect>("Sounds/Mage/mageReady");
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            //GraphicsDevice.Clear(Color.Crimson);
            this.DrawBackgroundImage(backgroundImage);
            this.DrawCharacter(1);
            if (this.GetModel().GetHoverLeft() == true)
                this.DrawImage(btn_left_click, new Rectangle(287, 225, btn_left_click.Width, btn_left_click.Height));
            else
                this.DrawImage(btn_left, new Rectangle(287, 225, btn_left.Width, btn_left.Height));
            if (this.GetModel().GetHoverRight() == true)
                this.DrawImage(btn_right_click, new Rectangle(585, 225, btn_right_click.Width, btn_right_click.Height));
            else
                this.DrawImage(btn_right, new Rectangle(585, 225, btn_right.Width, btn_right.Height));
            base.Draw(gameTime);
            if (this.GetModel().lockMenu)
                this.DrawBackgroundImage(backgroundGetReady);
        }

        public void DrawCharacter(int selectedCharacter)
        {
            string manaInfo;
            if (this.GetModel().listCharacter[this.GetModel().selectedCharacter].mana == 0)
            {
                manaInfo = "NA";
            }
            else
            {
                manaInfo = this.GetModel().listCharacter[this.GetModel().selectedCharacter].mana.ToString();
            }

            this.DrawFont(this.GetModel().listCharacter[this.GetModel().selectedCharacter].name, new Vector2(100, 48), Color.White);
            this.DrawFont2(this.GetModel().listCharacter[this.GetModel().selectedCharacter].life.ToString(), new Vector2(150, 95), Color.Black);
            this.DrawFont2(this.GetModel().listCharacter[this.GetModel().selectedCharacter].attack.ToString(), new Vector2(150, 113), Color.Black);
            this.DrawFont2(this.GetModel().listCharacter[this.GetModel().selectedCharacter].defense.ToString(), new Vector2(150, 130), Color.Black);
            this.DrawFont2(this.GetModel().listCharacter[this.GetModel().selectedCharacter].attackSpeed.ToString(), new Vector2(150, 149), Color.Black);
            this.DrawFont2(manaInfo, new Vector2(150, 167), Color.Black);
            this.DrawFont2(this.GetModel().listCharacter[this.GetModel().selectedCharacter].range.ToString(), new Vector2(150, 185), Color.Black);
            this.DrawFont2(this.GetModel().listCharacter[this.GetModel().selectedCharacter].speed.ToString(), new Vector2(150, 203), Color.Black);
            this.DrawFont2(this.GetModel().listCharacter[this.GetModel().selectedCharacter].specialAttack.ToString(), new Vector2(150, 220), Color.Black);    
       
            //image du personnage
            this.characterImage = Content.Load<Texture2D>(this.GetModel().listCharacter[this.GetModel().selectedCharacter].imgSelection);
            this.DrawImage(characterImage, new Rectangle(400,180, 145, 190));
        
        }

        protected void DrawFont2(string texte, Vector2 position, Color color)
        {
            spriteBatch.Begin();
            spriteBatch.DrawString(font2, texte, position, color);
            spriteBatch.End();
        }
    }
}
